package com.test.reggie.model.fragment.home;

import com.test.reggie.base.BaseObserver;
import com.test.reggie.base.BasePresenter;
import com.test.reggie.bean.AddShoppingCartBean;
import com.test.reggie.bean.CategoryListBean;
import com.test.reggie.bean.DishListBean;
import com.test.reggie.bean.ShoppingCartListBean;
import com.test.reggie.bean.StringBean;

import java.util.Map;

public class HomePrensenter extends BasePresenter<HomeView> {
    public HomePrensenter(HomeView baseView) {
        super(baseView);
    }

    /**
     * 根据条件查询分类数据
     */
    public void categoryList() {
        addDisposable(apiServer.categoryList(), new BaseObserver<CategoryListBean>() {
            @Override
            public void onSuccess(CategoryListBean bean) {
                baseView.categoryListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据条件查询对应的菜品数据
     *
     * @param categoryId
     */
    public void dishList(String categoryId) {
        addDisposable(apiServer.dishList(categoryId), new BaseObserver<DishListBean>() {
            @Override
            public void onSuccess(DishListBean bean) {
                baseView.dishListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据条件查询套餐数据
     *
     * @param categoryId
     */
    public void setmealList(String categoryId) {
        addDisposable(apiServer.setmealList(categoryId), new BaseObserver<DishListBean>() {
            @Override
            public void onSuccess(DishListBean bean) {
                baseView.dishListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 添加购物车
     *
     * @param map
     */
    public void addShoppingCart(Map<String, Object> map) {
        addDisposable(apiServer.addShoppingCart(map), new BaseObserver<AddShoppingCartBean>() {
            @Override
            public void onSuccess(AddShoppingCartBean bean) {
                baseView.addShoppingCartSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 查看购物车
     *
     * @param userId
     */
    public void shoppingCartList(String userId) {
        addDisposable(apiServer.shoppingCartList(userId), new BaseObserver<ShoppingCartListBean>() {
            @Override
            public void onSuccess(ShoppingCartListBean bean) {
                baseView.shoppingCartListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 清空购物车
     *
     * @param userId
     */
    public void cleanShoppingCart(String userId) {
        addDisposable(apiServer.cleanShoppingCart(userId), new BaseObserver<StringBean>() {
            @Override
            public void onSuccess(StringBean bean) {
                baseView.cleanShoppingCartSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 编辑购物车
     *
     * @param map
     */
    public void updateShoppingCart(Map<String, Object> map) {
        addDisposable(apiServer.updateShoppingCart(map), new BaseObserver<AddShoppingCartBean>() {
            @Override
            public void onSuccess(AddShoppingCartBean bean) {
                baseView.addShoppingCartSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
